import random
from flask import Flask,request,render_template,url_for,redirect
app = Flask(__name__)

file = open("../登录注册窗口/配置文件/poker.txt", "r", encoding='utf-8')

all_poker = file.read().split('\n')
# print(all_poker)


@app.route("/")
@app.route("/poker_choice/<int:take_num>",methods=["GET","POST"])
def choice_poker(take_num=None):
    if not take_num:
        take_num = 1
    # colors = ["红桃","黑桃","方片","梅花"]
    # cards = ["1","2","3","4","5","6","7","8","9","10","J","Q","K"]
    # kings = ["big cat","small cat"]
    #
    # # all_poker = []
    # for co_p in colors:
    #     for ca_p in cards:
    #         kings.append(co_p+ca_p)
    #         # all_poker.append(co_p+ca_p)
    # print(kings)

    cat_cage = ["big cat","small cat"]

    choosed_poker = []

    unchoosed_poker = []
    # all_poker = cat_cage.copy()

    while take_num > 0:
        if not unchoosed_poker:
            unchoosed_poker = all_poker

        res_list = list(set(unchoosed_poker) ^ set(choosed_poker))
        poker = random.choice(res_list)
        choosed_poker.append(poker)
        if "cat" in poker:
            continue
        take_num -= 1
        num_cats = 0
        score_list = []
        score_dict = {"A": 1, "J": 11, "Q": 12, "K": 13}
        for pk in choosed_poker:
            # if "cat" in poker:
            if pk in cat_cage:
                num_cats += 1
            else:
                try:
                    if len(pk) == 4:
                        score = int(pk[3])
                    else:
                        score = int(pk[3:])
                except:
                    score = score_dict[pk[-1]]
                score_list.append(score)
        print(choosed_poker)
        # print
        print(score)
        s = sum(score_list) * (2 ** num_cats)
    return render_template('take_poker.html', sum_num=s, take_poker=choosed_poker)
    # else:
    #     return ",".join(choosed_poker)
        # print(unchoosed_poker)



if __name__ == '__main__':
    # choice_poker()
    app.run(debug=True)